package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.common.StatusCode;
import com.example.demo.model.Dishes;
import com.example.demo.model.Ingredients;
import com.example.demo.service.RecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class RecommendationController {
    @Autowired
    private RecommendationService recommendationService;


    //    @GetMapping("/recommendations/{userId}")
//    public String getRecommendations(@PathVariable Long userId) {
//        // 根据用户 ID 获取推荐菜品列表
//        String recommendations = recommendationService.getRecommendations(userId.toString());
//        return recommendations;
//    }

    @GetMapping("/recommendations/ingredients/{name}")
    public ResponseEntity<Result<List<Ingredients>>> getRecommendedIngredients(@PathVariable String name) {
        // 根据用户 ID 获取推荐食材列表
        List<Ingredients> recommendedIngredients = recommendationService.getRecommendedIngredients(name);
        if (recommendedIngredients != null && !recommendedIngredients.isEmpty()) {
            return ResponseEntity.ok(new Result<>(true, StatusCode.OK, "获取推荐食材成功", recommendedIngredients));
        } else {
            return ResponseEntity.ok(new Result<>(false, StatusCode.ERROR, "未找到推荐食材", null));
        }
    }

    @GetMapping("/recommendations/food/{name}")
    public ResponseEntity<Result<List<Dishes>>> getRecommendedFood(@PathVariable String name) {
        // 根据用户 ID 获取推荐美食链表
        System.out.println(name);
        List<Dishes> recommendedFood = recommendationService.getRecommendedFood(name);
        System.out.println(recommendedFood);
        if (recommendedFood != null && !recommendedFood.isEmpty()) {
            return ResponseEntity.ok(new Result<>(true, StatusCode.OK, "获取推荐美食成功", recommendedFood));
        } else {
            return ResponseEntity.ok(new Result<>(false, StatusCode.ERROR, "未找到推荐美食", null));
        }
    }
}
